import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-07-27
 * Time: 9:13
 */
public class Test {
    public static void main(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        //设置key对应的value
        treeMap.put("hello",3);
        treeMap.put("abc",4);
        treeMap.put("the",2);
        treeMap.put("abs",4);
        //返回Key对应的value
        Integer a = treeMap.get("abc");
        System.out.println(a);
        //返回key对应的value，key不存在，则返回默认值
        Integer b = treeMap.getOrDefault("hi",100);
        System.out.println(b);
        //删除key对应的映射关系
        Integer c = treeMap.remove("abc");
        System.out.println(c);
        //返回所有key的不重复集合
        Set<String> set = treeMap.keySet();
        System.out.println(set);
        //返回所有value的可重复集合
        Collection<Integer> ret = treeMap.values();
        System.out.println(ret);
        //返回所有的key-value映射关系
        Set<Map.Entry<String,Integer>> set1 = treeMap.entrySet();
        for (Map.Entry<String,Integer> e : set1) {
            System.out.println("Key: " + e.getKey() + " Value: " + e.getValue());
        }
        System.out.println(set1);
        //判断是否包含key
        boolean b1 = treeMap.containsKey("abs");
        System.out.println(b1);
        //判断是否包含value
        boolean b2 = treeMap.containsValue(3);
        System.out.println(b2);
    }

    public static void main1(String[] args) {
        BinarySearchTree searchTree = new BinarySearchTree();
        searchTree.insert(34);
        searchTree.insert(21);
        searchTree.insert(22);
        searchTree.insert(3);
        searchTree.insert(67);


//        searchTree.inOrder(searchTree.root);
//        System.out.println();
//
//        BinarySearchTree.TreeNode ret = searchTree.find(3);
//        System.out.println(ret.val);
//        System.out.println();

//        searchTree.remove(3);
//        searchTree.inOrder(searchTree.root);

    }
}
